import java.util.Scanner;

public class Number {

	private static final int MAX_BASE = 16;
	private static final String pattern = "0123456789ABCDEF";

	public static String convertTo(int n, int base) {
		String result = "";

		// base is too big or too small
		if ((base > MAX_BASE) || (base < 2))
			return null;

		// n is equal to 0 -> return "0"
		if (n == 0)
			return "0";

		// process until n > 0
		while (n > 0) {
			result = pattern.charAt(n % base) + result;
			n /= base;
		}
		return result;
	}

	public static void main(String[] args) {
		/*
		 * int number; int nbase; Scanner odczyt = new Scanner(System.in);
		 * number = odczyt.nextInt(); nbase = odczyt.nextInt();
		 * System.out.println("Wynik: " + convertTo(number,nbase));
		 */
		System.out.println("123 w systemie 12 = " + convertTo(123, 12));
	}

}